package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.mapper.OrderDetailsMapper;
import com.qf.myexception.ServiceException;
import com.qf.pojo.OrderDetails;
import com.qf.service.OrderDetailsService;
import com.qf.utils.Constant;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderDetailsServiceImpl extends ServiceImpl<OrderDetailsMapper, OrderDetails> implements OrderDetailsService {

    @Autowired
    OrderDetailsMapper orderDetailsMapper;

    @Override
    public List<OrderDetails> findOne(String orderId) {
        QueryWrapper<OrderDetails> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id", orderId);
        List<OrderDetails> list = orderDetailsMapper.findByOrderId(wrapper);
        if (list != null)
            return list;
        throw new ServiceException(201, "查询异常");
    }

    @Override
    public ResultMsg add(List<OrderDetails> orderDetails) {
        boolean b = this.saveBatch(orderDetails);
        if (b)
            return ResultMsg.SUCCESS();
        return ResultMsg.FAILED(Constant.LZY + 2, "生成订单详情失败");
    }
}
